<test>
    <create_query>
        CREATE TABLE table_ip_trie
        (
            ip String,
            ver UInt8,
            val Float32
        ) ENGINE = TinyLog
    </create_query>

    <create_query>
        INSERT INTO table_ip_trie
        SELECT
            IPv4NumToString(ipv4) || '/' || toString(rand() % 17 + 16) as ip,
            4 as ver,
            val
        FROM generateRandom('ipv4 UInt32, val Float32', 0, 30, 30)
        LIMIT 200000
    </create_query>

    <create_query>
        INSERT INTO table_ip_trie
        SELECT
            IPv6NumToString(ipv6) || '/' || toString(rand() % 65 + 64) as ip,
            6 as ver,
            val
        FROM generateRandom('ipv6 FixedString(16), val Float32', 0, 30, 30)
        LIMIT 2500000
    </create_query>

    <create_query>
        CREATE DICTIONARY dict_ip_trie
        (
            ip String,
            ver UInt8,
            val Float32
        )
        PRIMARY KEY ip
        SOURCE(CLICKHOUSE(DB 'default' TABLE 'table_ip_trie'))
        LAYOUT(IP_TRIE())
        LIFETIME(300)
    </create_query>

    <create_query>
        CREATE TABLE dict_ip_trie_table
        (
            `ip` String,
            `ver` UInt8,
            `val` Float32
        ) ENGINE = Dictionary(default.dict_ip_trie)
    </create_query>

    <create_query>
        CREATE TABLE table_ip_from_dict (`ip` String, `ver` UInt8) ENGINE = TinyLog
    </create_query>
    <create_query>
        INSERT INTO table_ip_from_dict
        SELECT splitByChar('/', ip )[1] as ip, ver FROM dict_ip_trie_table
    </create_query>

    <query>
        SELECT dictGetFloat32('default.dict_ip_trie', 'val', tuple(rand32()))
        FROM numbers(500000) FORMAT Null
    </query>

    <query>
        SELECT dictGetFloat32('default.dict_ip_trie', 'val', tuple(randomFixedString(16)))
        FROM numbers(500000) FORMAT Null
    </query>

    <query>
        SELECT dictGetFloat32('default.dict_ip_trie', 'val', tuple(IPv6StringToNum(ip)))
        FROM table_ip_from_dict
        WHERE ver == 4
        LIMIT 500000 FORMAT Null
    </query>

    <query>
        SELECT dictGetFloat32('default.dict_ip_trie', 'val', tuple(IPv6StringToNum(ip)))
        FROM table_ip_from_dict
        WHERE ver == 6
        LIMIT 500000 FORMAT Null
    </query>

    <drop_query>DROP TABLE IF EXISTS table_ip_from_dict</drop_query>
    <drop_query>DROP TABLE IF EXISTS dict_ip_trie_table</drop_query>
    <drop_query>DROP DICTIONARY IF EXISTS default.dict_ip_trie</drop_query>
    <drop_query>DROP TABLE IF EXISTS table_ip_trie</drop_query>
</test>
